Imports Microsoft.VisualBasic
Imports System.Data.SqlClient

Public Class MyStringBuilder
    Protected s As New StringBuilder
    Public Cmd As SqlCommand

    Public Sub New()
        Me.Cmd = New SqlCommand
        Me.Cmd.CommandType = Data.CommandType.Text
    End Sub

    Public Sub New(ByVal createSqlCommand As Boolean)
        If createSqlCommand = True Then
            Me.Cmd = New SqlCommand
            Me.Cmd.CommandType = Data.CommandType.Text
        End If
    End Sub

    Public Sub AddWithValue(ByVal paremeterName As String, ByVal value As Object)
        Me.Cmd.Parameters.AddWithValue(paremeterName, value)
    End Sub

    Public Overridable Function AppendFormat(ByVal format As String, ByVal ParamArray args() As Object) As StringBuilder
        MyObj.SetDateLocale("")
        s.AppendFormat(format, args)
        'MyObj.SetDateLocale("zh-TW")

        Return s
    End Function

    Public Overridable Function AppendFormat(ByVal format As MyStringBuilder, ByVal ParamArray args() As Object) As StringBuilder
        For Each parameter As SqlParameter In format.Cmd.Parameters
            Me.AddWithValue(parameter.ParameterName, parameter.Value)
        Next

        Return Me.AppendFormat(format.ToString(), args)
    End Function

    Public Shared Function Format(ByVal fmt As String, ByVal ParamArray args() As Object) As String
        Dim s As String

        MyObj.SetDateLocale("")
        s = String.Format(fmt, args)
        'MyObj.SetDateLocale("zh-TW")

        Return s
    End Function

    Public Overrides Function ToString() As String
        Return Me.s.ToString()
    End Function

    Public Property Length() As Integer
        Get
            Return s.Length
        End Get
        Set(ByVal value As Integer)
            s.Length = value
        End Set
    End Property

    Public Property CommandType() As Data.CommandType
        Get
            Return Me.Cmd.CommandType
        End Get
        Set(ByVal value As Data.CommandType)
            Me.Cmd.CommandType = value
        End Set
    End Property
End Class
